package com.juguo.charginganimation.View.fragment;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.juguo.charginganimation.R;
import com.juguo.charginganimation.utils.UITools;
import com.juguo.charginganimation.View.activity.AboutActivity;
import com.juguo.charginganimation.View.activity.FavoritessActivity;
import com.juguo.charginganimation.View.activity.HelpActivity;
import com.juguo.charginganimation.View.activity.PrivacyActivity;
import com.juguo.charginganimation.View.activity.UserAgreementActivity;
import com.juguo.charginganimation.Viewmodel.PersonalCenterViewModel;
import com.juguo.charginganimation.databinding.PersonalCenterFragmentBinding;

import org.jetbrains.annotations.NotNull;

public class PersonalCenterFragment extends Fragment {

    private PersonalCenterViewModel mViewModel;
    private PersonalCenterFragmentBinding binding;
    public static PersonalCenterFragment newInstance() {
        return new PersonalCenterFragment();
    }

    @Override
    public void onAttach(@NonNull @NotNull Context context) {
        super.onAttach(context);
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.personal_center_fragment, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(PersonalCenterViewModel.class);
        //修复标题栏与状态栏重叠
        UITools.fitTitleBar(getActivity(), getView());
        binding.tvTitle.setText("个人中心");
        ocClick();
    }

    private void ocClick() {
        binding.linearLayout3.setOnClickListener(v -> {
//            FragmentManager fm = getActivity().getSupportFragmentManager();
//            FragmentTransaction beginTransaction = fm.beginTransaction();
//            beginTransaction.replace(R.id.layout_rotate_qh, new FavoritesFragment());
//            beginTransaction.addToBackStack(null);
//            beginTransaction.commit();
            Intent intent = new Intent(getContext(), FavoritessActivity.class);
            startActivity(intent);
        });
        binding.linearLayout2.setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), PrivacyActivity.class);
            startActivity(intent);
        });
        binding.linearLayoutGywm.setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), AboutActivity.class);
            startActivity(intent);
        });
        binding.linearLayoutLxkf.setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), HelpActivity.class);
            startActivity(intent);
        });
        binding.linearLayoutYhxy.setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), UserAgreementActivity.class);
            intent.putExtra("url", "file:///android_asset/web/UserLicenseAgreement.html");
            startActivity(intent);
        });
    }

}